<template>
  <div>
    <el-radio-group v-model="radio">
      <el-radio
        @change="changeAmType"
        v-for="(item,index) in amTypeList"
        :label="index"
        :key="item.anTypeName"
      >{{item.anTypeName}}</el-radio>
    </el-radio-group>

    <div>
      <el-radio-group v-model="childrenRadio">
        <el-radio
          @change="changeChildren"
          v-for="(item,index) in childrenTypeList"
          :label="index"
          :key="item"
        >{{item}}</el-radio>
      </el-radio-group>
    </div>

    <el-button @click="addList">添加数据</el-button>
    <el-table
      :data="amList"
      style="width: 100%">
      <el-table-column
        label="序列"
        width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.amId }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="农资名称"
        width="180">
        <template slot-scope="scope">

            <p>{{ scope.row.anName }}</p>
        </template>
      </el-table-column>
      <el-table-column
        label="使用量"
        width="180">
        <template slot-scope="scope">
          <!--.number 修饰符 .center .esc .13-->
            <el-input  v-model.number="scope.row.count">{{ scope.row.count }}</el-input>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button @click="getRes">获取内容</el-button>

  </div>
</template>

<script>
import {getAmList, getAmType} from '../api/am.js';
export default {
  mounted() {
    this.getAm();
    this.getList();
  },

  data() {
    return {
      amTypeList: [],
      radio: '-1',
      childrenRadio: '-1',
      childrenTypeList: [],
      chooseFather: '',
      amList: []
    };
  },

  methods: {
    async getAm() {
      this.amTypeList = await getAmType();
    },

    async getList() {
      this.amList = await getAmList();
      this.amList.forEach(item => this.$set(item,'count',0));// 只要一个属性变成侦听器属性 就可以就可以双向绑定
      console.log(this.amList);

    },
    addList() {
    },

    changeAmType(label) {
      this.chooseFather = this.amTypeList[label].anTypeName;
      this.childrenTypeList = this.amTypeList[label].children;
    },
    changeChildren(childrenLabel) {
      console.log(this.chooseFather, this.childrenTypeList[childrenLabel]);
      //
    },

    handleEdit(index,row) {
      console.log(index,row);

    },
    handleDelete(index, row) {
      console.log(index, row);

    },

    getRes() {
      console.log(this.amList);
    }
  },
};
</script>
<style>
.el-radio__input {
  display: none;
}
</style>
